package demo.Test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Objects;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/16-08-16-16:33
 * @Description：demo.Test
 */
public class demo2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = null;
        TreeSet<Student> set = new TreeSet<>();
        while(!((str = sc.nextLine()).equals("quit"))){
            String[] s = str.split(".");
            set.add(new Student(s[0],s[1],Integer.valueOf(s[2])));
        }
        for (Student student : set) {
            System.out.println(student);
        }
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("src/student.txt"));
            oos.writeObject(set);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(oos != null){
                    oos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
class Student implements Comparator, Serializable {
    private String id;
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(id, student.id) && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, age);
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    @Override
    public int compare(Object o1, Object o2) {
        Student stu1 = (Student)o1;
        Student stu2 = (Student)o2;
        if(stu1.getName().equals(stu2.getName())){
            if(stu1.getAge() == stu2.getAge()){
                return stu1.getId().compareTo(stu2.getId());
            }else{
                return stu2.getAge()-stu1.getAge();
            }
        }else{
            return stu1.getName().compareTo(stu2.getName());
        }
    }
}